package com.effectiv.gooruda.rest.service.api;

import java.util.List;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;

import lombok.Getter;
import lombok.Setter;

import com.effectiv.gooruda.rest.docs.annotation.Api;
import com.effectiv.gooruda.rest.docs.annotation.ApiHeader;
import com.effectiv.gooruda.rest.docs.annotation.ApiHeaders;
import com.effectiv.gooruda.rest.docs.annotation.ApiMethod;
import com.effectiv.gooruda.rest.docs.pojo.ApiVerb;
import com.effectiv.gooruda.rest.domain.Role;
import com.effectiv.gooruda.rest.ext.SecurityContextHolder;

@Path("/role")
@Api(name = "Role API", description = "Role management API.")
public abstract class RoleService {
	
	private final String COLLECTION_BASE = "c_app_role_";
	
	@Getter @Setter
	@Autowired
	private MongoTemplate template;

	protected String getCollection(){
		return COLLECTION_BASE + SecurityContextHolder.get().getId();
	}
	
	@ApiMethod(path = "/api/role", verb = ApiVerb.POST, description = "Save role details.", 
			produces = { MediaType.APPLICATION_JSON }, consumes = { MediaType.APPLICATION_JSON })
	@ApiHeaders(headers = {
			@ApiHeader(name = "signature", description = "Authentication signature."),
			@ApiHeader(name = "public-key", description = "Public key of the application.") })
	@POST	
	@Produces(MediaType.APPLICATION_JSON)
	public abstract Response save(Role role);

	public abstract Role findByName(String roleName);

	public abstract Role findOne(String id);

	public abstract Role addPermission(String roleName, String permission);

	public abstract Role addPermissions(String roleName, List<String> permissions);

}
